package jsu.yym.tiktok.test;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.util.*;

import java.util.List;
import java.util.Properties;


@RestController
@CrossOrigin
public class ProseController {
    public String generateCopy(List<String> keywords) {
        // 初始化Stanford NLP管道
        Properties props = new Properties();
        props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

        // 将关键字连接成一个文本字符串
        String text = String.join("，", keywords);

        // 创建Annotation对象并进行NLP处理
        Annotation document = new Annotation(text);
        pipeline.annotate(document);

        // 获取处理结果
        List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
        StringBuilder generatedText = new StringBuilder();

        for (CoreMap sentence : sentences) {
            for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                String word = token.get(CoreAnnotations.TextAnnotation.class);
                generatedText.append(word);
            }
        }

        // 生成文案
        String finalText = generatedText.toString();
        System.out.println("生成的文案：\n" + finalText);
        return finalText;
    }

}


